package com.me.modules.sys.controller;

import java.util.ArrayList;
import java.util.List;

import com.me.modules.common.annotation.SysLog;
import com.me.modules.common.controller.BaseController;
import com.me.modules.common.utils.*;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import com.me.modules.sys.entity.TimetblWorkdateEntity;
import com.me.modules.sys.service.TimetblWorkdateService;

import javax.servlet.http.HttpServletRequest;


/**
 * 系统节假日时间定义
 *
 * @author lill
 * @email lill5270@163.com
 * @date 2019-01-08 16:56:49
 */
@Controller
@RequestMapping("/sys/timetblworkdate")
public class TimetblWorkdateController extends BaseController{
	@Autowired
	private TimetblWorkdateService timetblWorkdateService;


	/**
	 * 列表
	 */
	@RequestMapping("/list")
	//@RequiresPermissions("timetblworkdate:list")
	@SysLog("查询工作时间模板")
	public String  list(TimetblWorkdateEntity timetblWorkdate, Model model , HttpServletRequest request){
		//Query query = new Query(params);
		List<TimetblWorkdateEntity> timetblWorkdateList = new ArrayList<TimetblWorkdateEntity>();
		if(timetblWorkdate.getTblId()!=null){
			timetblWorkdateList = timetblWorkdateService.queryListByBean(timetblWorkdate);
		}
		model.addAttribute("timetblWorkdateList",timetblWorkdateList);
		model.addAttribute("timetblWorkdate",timetblWorkdate);
		//model.addAttribute("page",page);
		return "sys/timetblworkdate/list";
	}


	/**
	 * 信息
	 */
	@RequestMapping("/info")
	//@RequiresPermissions("timetblinfo:info")
	@SysLog("查询工作时间列表")
	public String info( Model model,Long id, HttpServletRequest request){
		TimetblWorkdateEntity timetblWorkdate = timetblWorkdateService.queryObject(id);
		model.addAttribute("timetblWorkdate",timetblWorkdate);
		return "sys/timetblworkdate/edit";
	}



	@RequestMapping(value = "save",method = RequestMethod.POST)
	//@RequiresPermissions("timetblinfo:save")
	@ResponseBody
	public Result save(TimetblWorkdateEntity timetblWorkdate){

		if(timetblWorkdate.getId()==null) {
			timetblWorkdateService.save(timetblWorkdate);
		}else {
			timetblWorkdateService.update(timetblWorkdate);
		}
		//CodeUtils.getCodeName("time_status",timetblWorkdate.getWorkDateType());
		return Result.ok().put("timetblWorkdate",timetblWorkdate).put("beginDate", DateUtils.format(timetblWorkdate.getBeginDate(),DateUtils.DATE_TIME_PATTERN))
				.put("endDate", DateUtils.format(timetblWorkdate.getEndDate(),DateUtils.DATE_TIME_PATTERN)).put("workDateType",CodeUtils.getCodeName("workDateType",timetblWorkdate.getWorkDateType()));
	}




	/**
	 * 修改
	 */
	@RequestMapping("/update")
	@RequiresPermissions("timetblworkdate:update")
	public Result update(@RequestBody TimetblWorkdateEntity timetblWorkdate){
		timetblWorkdateService.update(timetblWorkdate);

		return Result.ok();
	}


	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	@ResponseBody
	public Result edit(Long id){
		if(timetblWorkdateService.delete(id)<1){
			return Result.error("删除节假日时间失败");
		}
		return Result.ok("删除节假日时间成功");
	}
}
